import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import WindiCSS from 'vite-plugin-windicss'
import Components from 'unplugin-vue-components/vite'
import Pages from 'vite-plugin-pages'
import AutoImport from 'unplugin-auto-import/vite'
const path = require('path');

// 0. 配置浏览器 document title
// 1. 配置打包文件名规范 -- rollupOptions
// 2. 超大资源拆分 -- manualChunks
// 3. 清除 console 和 debugger -- vite-plugin-compression

// https://vitejs.dev/config/
export default defineConfig({
  // base:'dist',
  plugins: [
    vue({
      reactivityTransform: true,
    }),
    Pages({
      dirs: 'src/views'
    }),
    vueJsx(),
    WindiCSS(),
    AutoImport({
      imports: [
        'vue',
        'vue/macros',
        'vue-router',
        '@vueuse/core',
      ],
      dts: true,
      dirs:[
        'src/store/modules',
        'src/service/api',
      ]
    }),
    // ui库解析器，也可以自定义
    Components({
      // 指定组件位置，默认是src/components
      dirs: ['src/components/common'],
      // ui库解析器
      // resolvers: [ElementPlusResolver()],
      extensions: ['vue'],
      // 配置文件生成位置
      dts: 'components.d.ts'
    }),

  ],
  resolve: {
    alias: {
      '~': path.resolve('./'),
      '@': path.resolve(__dirname,'src')
    }
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${path.resolve('src/styles/theme.less')}";`,
        },
        javascriptEnabled: true
      }
    }
  },
  server: {
    host: '0.0.0.0',
    port: 3000,
    open: true,
    proxy:{
      '/api': {
        target: 'http://localhost:3200/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '') // 重写路径把路径变成空字符
      }
    }
  },
  // build: {
  //   // sourcemap: true, 
  //   terserOptions: {
  //     compress: {
  //       drop_console:true,
  //       drop_debugger:true
  //     }
  //   }
  // }
})
